#!/bin/bash

# testcase build
gcc -static -O0 test.c -o test

# trace gen
objdump -d test > test.asm
bash awk '/^[0-9a-f]+ <.*>:/{addr=strtonum("0x"$1); getline; print addr, $0}' test.asm > prospero.trace


declare -a time_array
# 运行所有模型
for config in timing_cpu.py; do
    echo "Running $config..."
    start=$(date +%s.%N)
    sst -n 1 $config --output-directory=./${config%.*}_out
    end=$(date +%s.%N)
    exec_time=($(echo "$end - $start" | bc -l))

    time_array+=("$exec_time")
done

# 提取仿真时间
echo "CPU Model | insts    | Simulation Time (s) | MIPS"
echo "------------------------------------"
i=0
for dir in timing_cpu_out; do
    time=${time_array[$i]}
    insts=$(grep "instructions_retired" ./$dir/stats.csv | awk -F', ' '{print $7}')
    mips=$(echo "scale=2; $insts / (10^6 * $time)" | bc)
    echo "${dir%_out}  | $insts | $time | $mips"
    i=$((i+1))
done
